<template>
  <div>
    <el-input v-model="name" disabled>
      <el-button slot="append" icon="el-icon-s-grid" @click="openModal" />
    </el-input>

    <role-modal ref="model" :value="value" @ok="handleOK" />
  </div>
</template>

<script>
import roleModal from './Modal'
export default {
  name: 'RoleSingleSelect',
  components: {
    roleModal
  },
  model: {
    prop: 'value',
    event: 'change'
  },
  props: {
    width: {
      type: Number,
      default: 500,
      required: false
    },
    value: {
      type: String,
      default: '',
      required: false
    },
    disabled: {
      type: Boolean,
      required: false,
      default: false
    }

  },
  data() {
    return {
      visible: false,
      name: ''
    }
  },
  watch: {
    value: {
      immediate: true,
      handler: 'handleValue'
    }
  },
  methods: {
    openModal() {
      this.$refs.model.show()
    },
    handleValue() {
      if (this.value) {
        this.$api.system.role.get(this.value)
          .then(res => {
            this.name = res.data.name
          })
      } else {
        this.name = ''
      }
    },
    handleOK(value) {
      this.name = value.name
      this.$emit('changeSelect', value)
    }
  }
}
</script>

<style scoped>
</style>
